package org.neuedu.chapter07_0623.demo07;

public class FruitCreate {
    public Fruit createFruit(int num){
        if (num == 1) {
            return new Apple();
        } else if (num == 2) {
            return new Pear();
        } else if (num == 3) {
            return new Banana();
        }else{
            return null;
        }
    }

    public static void main(String[] args) {
        FruitCreate fruitCreate = new FruitCreate();
        Fruit fruit = fruitCreate.createFruit(3);
        if (fruit instanceof Apple) {
            Apple apple = (Apple)fruit;
            System.out.println(apple.name1);
        }

        if (fruit instanceof Pear) {
            Pear pear = (Pear)fruit;
            System.out.println(pear.name2);
        }

        if (fruit instanceof Banana) {
            Banana banana = (Banana)fruit;
            System.out.println(banana.name3);
        }
    }
}
